package com.etooling.framework.repository;

import com.etooling.framework.entity.ImportDataBatch;
import com.etooling.framework.svo.ReplyObj;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

@Repository
public interface ImportDataBatchRepository extends BaseRepository<ImportDataBatch> {
    @Transactional
    @Modifying
    @Query(value = "delete from import_data.import_bom where batch_id=?1 and component_type ='' and component_num='' ", nativeQuery = true)
    void cleanByBatch(String id);

    @Transactional
    @Modifying
    @Query(value = "update import_data.imp_data_bach set status = ?2 where id=?1 ", nativeQuery = true)
    int updateStatusByBatchId(String fileId, String statusUploadDoing);

    @Transactional
    @Modifying
    @Query(value = "update import_data.imp_data_bach set status = ?2,done_time = NOW(),impl_memo = ?3  where id=?1 ", nativeQuery = true)
    void updateCompletedStatusByBatchId(String batchId, String status, String implMemo);

    @Query(nativeQuery = true, value = "select * from import_data.imp_data_bach where id = ?1 and upload_login_id = ?2 and upload_company_id = ?3 ")
    ImportDataBatch checkStatus(String fileId, String loginId, String companyId);

    @Query(nativeQuery = true, value = "select count(*) from import_data.imp_data_bach where upload_login_id = ?1 and upload_company_id = ?2 and status ='提交中' ")
    int checkStatusCount(String loginId, String companyId);

    @Transactional
    @Modifying
    @Query(value = "update import_data.imp_data_bach set status = ?3,error_memo = ?2 where id=?1 ", nativeQuery = true)
    void updateErrorByBatchId(String batchId, String message, String statusSubmitFaile);

}
